package cn.lingnan.view;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import cn.lingnan.DAO.MenuDAO;
import cn.lingnan.dto.Menu;
import cn.lingnan.model.MenuInfoTableModel;

public class StaffOrderView extends JPanel implements ActionListener{

	       private MenuDAO md;
	       //上面
			private JPanel toolBarPanel;
		
			private JPanel searchPanel;
			private JLabel nameLabel;
			private JTextField nameSearchTF;
			private JButton searchBtn;
			
			private JPanel opePanel;
			private JButton addBtn,updateBtn,deleteBtn;
			
			
			//中间
			private JScrollPane tableScrollPane;
			private JTable orderTable;
		
			
			//下面
			private JPanel bottomPanel;
			private JLabel countInfoLabel;
			
			private MenuInfoTableModel menuInfoTableModel;
			private JFrame jFrame;
			private MenuDAO menuDAO=new MenuDAO();
			
			public StaffOrderView(JFrame jFrame) {
				this.setLayout(new BorderLayout());
				initView();
				this.jFrame = jFrame;
			}
			
			
			private void initView() {
				 
				toolBarPanel = new JPanel(new BorderLayout()); 
				
				searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); 
				nameLabel = new JLabel("菜色编号");
				nameSearchTF = new JTextField(10);
				
				searchBtn = new JButton("搜索",new ImageIcon("static\\icon\\search.png"));
				searchBtn.addActionListener(this);
				
				opePanel =  new JPanel(new FlowLayout(FlowLayout.RIGHT)); 
				addBtn =new JButton("添加",new ImageIcon("static\\icon\\user_add.png"));
				updateBtn =new JButton("更新",new ImageIcon("static\\icon\\user_edit.png"));
				deleteBtn =new JButton("删除",new ImageIcon("static\\icon\\user_delete.png"));
				
				addBtn.addActionListener(this);
				updateBtn.addActionListener(this);
				deleteBtn.addActionListener(this);
				
				opePanel.add(addBtn);
				opePanel.add(updateBtn);
				opePanel.add(deleteBtn);
				 
				searchPanel.add(nameLabel);
				searchPanel.add(nameSearchTF);
				searchPanel.add(searchBtn);
				
				
				toolBarPanel.add(searchPanel,"West");
				toolBarPanel.add(opePanel,"East");
				

				
				
				//中间
				md=new MenuDAO();
			    Vector<Menu> vm=md.findAllMenu();
			    MenuInfoTableModel model=new MenuInfoTableModel(vm);		   
				orderTable = new JTable(model);	   
				orderTable = new JTable();
	    		tableScrollPane = new JScrollPane(orderTable);
	            
				//下面
				bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
				String str=Integer.toString(model.getRowCount());
				countInfoLabel = new JLabel("总共"+str+"条");
				bottomPanel.add(countInfoLabel);
				
				
				this.add(toolBarPanel,"North");
				this.add(tableScrollPane,"Center");
				this.add(bottomPanel,"South");
				
				this.setVisible(true);
				//refresh();
			}

			
	@Override
	      public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	 }

}
